<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">


<div th:replace="public/base_update :: html"></div>

<body>
<!-- Start Page Loading -->
<div id="loader-wrapper">
    <div id="loader"></div>
    <div class="loader-section section-left"></div>
    <div class="loader-section section-right"></div>
</div>
<!-- End Page Loading -->


<!-- START MAIN -->
<!-- START WRAPPER -->


<!-- START CONTENT -->
<section id="content">
    <!--Form Advance-->
    <div class="row">
        <div class="col s12 m12 l12">
            <div class="card-panel">
                <h4 class="header2">入库单</h4>
                <div class="row">
                    <form class="col s12" id="send_form" action="">
                        <input type="hidden" id="id" name="id" th:value="${enterStore.id}">
                        <div class="row">
                            <div class="input-field col s4">
                                <input id="myPartsId" type="hidden"  th:value="${enterStore.partsId}" />
                                <select name="partsId" id="partsId">
                                </select>
                                <label for="partsId">请选择零配件</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s4">
                                <input id="num" name="num" type="text" th:value="${enterStore.num}" />
                                <label for="num">入库数量</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s4">
                                <input id="validity_time" name="validityTime" type="text" class="datepicker" th:value="${enterStore.validityTime}" />
                                <label for="validity_time">零配件有效期</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s4">
                                <input id="myStoreId" type="hidden"  th:value="${enterStore.storeId}" />
                                <select name="storeId" id="storeId">
                                </select>
                                <label for="storeId">请选择仓库</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s4">
                                <input id="verifier_opinion" name="verifierOpinion" type="text" th:value="${enterStore.verifierOpinion}"th:readonly="${roleName} != 'check'" />
                                <label for="verifier_opinion">校验员意见</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s4">
                                <input id="managersOpinion" name="managersOpinion" type="text" th:value="${enterStore.managersOpinion}" th:readonly="${roleName} != 'managers'" />
                                <label for="managersOpinion">经理意见</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s12">
                                <button id="send_btn" class="btn cyan waves-effect waves-light right" type="button"
                                        name="action">提交
                                    <i class="mdi-content-send right"></i>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>


<!-- ================================================
Scripts
================================================ -->

<script th:inline="javascript">

    $(document).ready(function() {
        getParts();
        getStore();
    });

    function getParts() {
        var partsIdSelect  = $("#partsId");

        var flag = $('#myPartsId').val();

        $.getJSON("/parts/getParts", function (result){
            if (flag == null || flag == "" ){
                partsIdSelect.prepend("<option value='0'>选择零配件</option>");

                $(result).each(function (i) {
                    partsIdSelect.append("<option value='" + this.id + "'>" + this.name + "</option>")
                });

            }else {
                for (var j = 0;j<result.length;++j){
                    if (flag == result[j].id){

                        partsIdSelect.append("<option value='" + result[j].id + "'>" + result[j].name + "</option>");
                    }
                }
                $(result).each(function (i) {
                    partsIdSelect.append("<option value='" + this.id + "'>" + this.name + "</option>")
                })
            }
            partsIdSelect.material_select();
        });
    }

    function getStore() {
        var storeIdSelect  = $("#storeId");

        var flag = $('#myStoreId').val();

        $.getJSON("/store/getStore", function (result){
            if (flag == null || flag == "" ){
                storeIdSelect.prepend("<option value='0'>选择仓库</option>");

                $(result).each(function (i) {
                    storeIdSelect.append("<option value='" + this.id + "'>" + this.name + "</option>")
                });

            }else {
                for (var j = 0;j<result.length;++j){
                    if (flag == result[j].id){

                        storeIdSelect.append("<option value='" + result[j].id + "'>" + result[j].name + "</option>");
                    }
                }
                $(result).each(function (i) {
                    storeIdSelect.append("<option value='" + this.id + "'>" + this.name + "</option>")
                })
            }
            storeIdSelect.material_select();
        });
    }


    $("#send_btn").click(function () {
        dialog.confirm('确定提交么?', function (index, layero) {
            var send_form = $('#send_form').serialize();
            console.log(send_form);
            $.ajax({
                type: "post",
                data: send_form,
                url: "/enterStore/add",
                dataType: "json",
                success: function (msg) {
                    if (msg.success) {
                        Materialize.toast(msg.message, 500,'',function () {
                            dialog.parentclose(true)
                        });
                    } else {
                        Materialize.toast(msg.message, 3000);
                    }
                },
                error: function ( ) {
                    Materialize.toast("网络异常");
                }
            });
        });
    });


</script>

</body>

</html>
